#include <bits/stdc++.h>
using namespace std;

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> pre(n + 1), a(n);
    for(int i = 0; i < n; i++) {
        cin >> a[i];
        pre[i + 1] = pre[i] + a[i];
    }
    deque<int> q;
    int ans = INT_MIN;
    q.push_back(0);
    for(int i = 0; i < n; i++) {
        while(q.size() && q.front() + m <= i) {
            q.pop_front();
        }
        ans = max(ans, pre[i + 1] - pre[q.front()]);
        while(!q.empty() && pre[q.back()] >= pre[i + 1]) q.pop_back();
        q.push_back(i + 1);
    }
    cout << ans << endl;
    return 0;
}